package com.spring.takeaway.serviceimpl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spring.takeaway.dao.FoodDao;
import com.spring.takeaway.dao.OrderDao;
import com.spring.takeaway.po.Food;
import com.spring.takeaway.po.Order;
import com.spring.takeaway.service.FoodService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author LCD
 * @Date 2022/6/12 14:43
 **/
@Service
public class FoodServiceImpl implements FoodService {
    @Autowired
    private OrderDao orderDao;

    @Autowired
    private FoodDao foodDao;
    @Override
    public List<Food> findListFood(Integer Id) {
        QueryWrapper wrapper  = new QueryWrapper();
        wrapper.eq("food_merid",Id);
        return this.foodDao.selectList(wrapper);
    }

    @Override
    public int insertOrder(Order order) {
//        order.setFood();
        order.setOrderId(1000);
        String s = JSON.toJSONString(order.getFoods());
        order.setFood(s);
        System.out.println(order);
        System.out.println(s);
        return this.orderDao.insertOrder(order);
    }

    @Override
    public List<Order> findListOrder(String phone) {
        List<Order> orderList = this.orderDao.getOrderList(phone);
        System.out.println(orderList.toString());
        return orderList;
    }
}
